/**
 * Created by Jacky
 *
 * brief :
 */

HW.App.factory('FirstCategoryFactory', function(){

    var F = {

        getBaseData : function(callback){
            HW.request.getFirstCategoryData({}, callback);
        },

        getLifeServiceData : function(callback){
            HW.request.getHomePageLifeServiceData({}, callback);
        },

        getHomeSlideBoxData : function(callback){
            var rowSize = 4,
                row = 2,
                panelSize = rowSize * row;

            F.getBaseData(function(data){
                var rs = [];
                var len = Math.ceil(data.length / panelSize);

                for(var i= 0; i<len; i++){
                    rs[i] = [];
                }

                var n= 0,
                    size = data.length;
                while(n < size){
                    var rsIndex = Math.floor(n / panelSize),
                        tmp = rs[rsIndex];

                    var ta = Math.floor(n%panelSize / rowSize),
                        tb = n % rowSize;
                    if(!angular.isArray(tmp[ta])){
                        tmp[ta] = [];
                    }

                    tmp[ta][tb] = data[n];

                    n++;
                }

                callback.call(null, rs);
            });
        },

        getHomeSubCategoryData : function(callback){
            var rowSize = 2;
            F.getLifeServiceData(function(ddata){
                var data = ddata.data;

                var rs = [];
                var len = Math.ceil(data.length / rowSize);

                for(var i= 0; i<len; i++){
                    rs[i] = [];
                }

                var n= 0,
                    size = data.length;
                while(n < size){
                    var rsIndex = Math.floor(n / rowSize),
                        tmp = rs[rsIndex];

                    var ta = n % rowSize;
                    tmp[ta] = data[n];

                    n++;
                }

                callback.call(null, {
                    title : ddata.title,
                    data : rs
                });
            });
        }

    };

    return F;
});